# -*- coding: utf-8 -*-
# @Time    : 2021/1/4 下午5:06
# @Author  : tgy

def test01():
    """
    文本文件读取会调用 encode把磁盘存储的二进制数据进行decode成 unicode，存在内存中
    二进制文件则直接读取内存数据，存储在 bytes中，如果需要，自己进行decode转码
    """
    with open('./README.md', mode='rt', encoding='utf-8', errors='ignore') as f:
        ...
        # content = f.read()
        # print(content)
        # content = f.read(10)
        # print(content)
        for line in f:
            ...
            print(line)


def test02():
    ...
    with open('./a.txt', mode='wt', encoding='utf-8') as wf, \
            open('./README.md', mode='rt', encoding='utf-8') as rf:

        while True:
            content = rf.readline()
            if not content:
                break
            wf.write(content)


def test03():
    ...
    with open("./README.md", mode='r+', encoding='utf-8') as rf:
        rf.write('哈哈')
        content = rf.read()
        print(content)


if __name__ == '__main__':
    test03()
